home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Windows News 2006 October
/
wn148cd2.iso
/
Windows
/
Travailler
/
QuickZip
/
quickzip_460013.exe
/
{app}
/
Scripts
/
Syncthronize.akp
< prev
next >
Wrap
Text File
|
2003-05-11
|
3KB
|
82 lines
//Compare and update the files in <Dir1> and <Dir2>.
//Backup overwrited file to <BackupChanges>.
const Dir1 = 'C:\1';
Dir2 = 'C:\2';
BackupChanges = 'C:\Temp\Backup.zip';
SubDir = True;
var Content1, Content2 : TStrings;
Path1,Path2 : String;
procedure PollDirectoryContents;
var i : integer;
begin
Path1 := AppendSlash(Dir1);
Path2 := AppendSlash(Dir2);
Content1.AddStrings(PollFileList(Path1+'*',SubDir));
Content2.AddStrings(PollFileList(Path2+'*',SubDir));
for i := 0 to Content1.count -1 do
content1.strings[i] := Copy(content1.strings[i], Length(Path1) + 1, length(content1.strings[i]) - Length(Path1));
for i := 0 to Content2.count -1 do
content2.strings[i] := Copy(content2.strings[i], Length(Path2) + 1, length(content2.strings[i]) - Length(Path2));
end;
procedure CheckNewFiles;
var i : integer;
begin
Writeln('Looking for new files...');
For i := 0 to Content1.count -1 do
begin
if not Fileexists(Path2 + Content1.strings[i]) then
begin
Writeln(Path1 + Content1.strings[i] + ' -> ' + Path2);
CopyFile(Path1 + Content1.strings[i],Path2 + Content1.strings[i] );
end;
end;
For i := 0 to Content2.count -1 do
begin
if not Fileexists(Path1 + Content2.strings[i]) then
begin
Writeln(Path2 + Content2.strings[i] + ' -> ' + Path1);
CopyFile(Path2 + Content2.strings[i],Path1 + Content2.strings[i]);
end;
end;
end;
procedure CompareFileDate;
var i,j : integer;
begin
Open(BackupChanges);
UseAddPath(True);
UseVerCtrl(True);
Writeln('Comparing existing files...');
For i := 0 to Content1.count -1 do
begin
j := Content2.Indexof(Content1.strings[i]);
if j <> -1 then
begin
if GetFileDatetime(Path1+Content1.strings[i]) > GetFileDatetime(Path2+Content2.strings[j]) then
begin
Writeln(Path1+Content1.strings[i] + ' -> ' + Path2+Content2.strings[j]);
Add(Path2+Content2.strings[j]);
DoAdd;
CopyFile(Path1+Content1.strings[i],Path2+Content2.strings[j]);
end else
if GetFileDatetime(Path1+Content1.strings[i]) < GetFileDatetime(Path2+Content2.strings[j]) then
begin
Writeln(Path1+Content1.strings[i] + ' <- ' + Path2+Content2.strings[j]);
Add(Path1+Content1.strings[i]);
DoAdd;
CopyFile(Path2+Content2.strings[j],Path1+Content1.strings[i]);
end;
end;
end;
end;
begin
Content1 := TStringList.create();
Content2 := TStringList.create();
PollDirectoryContents;
CheckNewFiles;
CompareFileDate;
Writeln('Completed!');
end.